<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of UsersQuery
 *
 * @author juwking
 */
require_once 'TableControl.php';

class UsersQuery2 extends TableControl {

    protected $user = 'root', $password, $dbase = 'wincon_mailing_db';

    function __construct() {
        parent::__construct();
    }

    function Select($param=null, $limit=null) {
        if (!is_int($param))
        //$queryString = "Select * from users where name like '%" . $param['name'] . "%' and surname like '%" . $param['surname'] . "%' and email like '%" . $param['email'] . "%' and login like '%" . $param['login'] . "%' and password like '%" . $param['password'] . "%'";
            $queryString = "Select * from users where name like '% :name %' and surname like '% :surname %' and email like '% :email %' and login like '% :login %' and password like '% :password %'";
        else
            $queryString = "Select * from users LIMIT   $param  ,  $limit;";
        $result = $this->pdo->prepare($queryString);
        $result->setFetchMode(PDO::FETCH_ASSOC);
        $result->execute(array(':name' => $param['name'],
            ':surname' => $param['surname'],
            ':email' => $param['email'],
            ':login' => $param['login'],
            ':password' => $param['password']
        ));

        return $result->fetchAll();
    }

    function login($param) {
        $queryString = "Select * from users where login like '" . $param['login'] . "' and password like '" . $param['password'] . "'";
        $result = $this->pdo->query($queryString) or die('Cannot open database');
        $result->setFetchMode(PDO::FETCH_ASSOC);
        return $result->fetch();
    }

    function Insert($param) {
        
    }

    function Update($param) {
        
    }

    function Delete($param) {
        
    }

    function getEmptyRecord() {

    }

    public function getTableName() {
        return 'users';
    }

    public function getColumns() {
        return array('users_id', 'users_organization_id', 'users_user_groups_id', 'name', 'surname', 'login', 'password', 'email');
    }

}

?>
